package com.lqh.studyproject.java8lambda;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName TestFilter
 * @Description studyproject
 * @Author bgy-lqh
 * @Date 2020/6/19 16:16
 * @Version filter相关例子
 **/
public class TestFilter {
    public static void main(String[] args) {
        List<Person> persionList = new ArrayList<Person>();
        persionList.add(new Person(1, "张三", "男", 8));
        persionList.add(new Person(2, "小小", "女", 2));
        persionList.add(new Person(3, "李四", "男", 25));
        persionList.add(new Person(4, "王五", "女", 8));
        persionList.add(new Person(5, "赵六", "女", 25));
        persionList.add(new Person(6, "大大", "男", 65));
        //1、查找年龄大于20岁的人数
        Long age=persionList.stream().filter(person -> person.getAge()>20).count();
        System.out.println(age);

        //2、查找年龄大于20岁，性别为男的人数
        Long ageSex=persionList.stream().filter(person -> person.getAge()>20).filter(person -> person.getSex().equals("男")).count();
        System.out.println(ageSex);
    }

}